<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('发送公告')"/>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" class="grid_tab" aria-expanded="true">新建公告</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" class="grid_tab" aria-expanded="false" onclick="refreshRecord()">已发送</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body jqgrid_box">
                            <form class="form-horizontal" method="post" id="prodForm">
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">选择用户：</label>
                                    <div class="col-sm-3">
                                        <label class="radio-inline i-checks">
                                            <input type="checkbox" name="sendUser" value="1"> <i></i> 全部店长</label>
                                        <label class="radio-inline i-checks">
                                            <input type="checkbox" name="sendUser" value="2"> <i></i> 全部老师</label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">公告内容：</label>
                                    <div class="col-sm-3">
                                        <div class="ibox-content">
                                            <div class="form-group">
                                                <div class="col-sm-12">
                                                    <textarea class='form-control' id="evaluate" name='evaluate' onkeyup='textAreaChange(this, 1000)' onkeydown='textAreaChange(this, 1000)' rows='5'></textarea>
                                                    <div class='text-right'>
                                                        <em style='color:red'>0</em>/<span>1000</span>
                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-3" style="text-align: center">
                                        <input class="btn btn-primary" type="button" onclick="save()" value="发送" style="margin-right: 20px">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div id="tab-2" class="tab-pane">
                        <div class="panel-body jqgrid_box">
                            <form id="noticeRecordForm" th:action="@{/notice/noticemessage/sendList}" class="form-inline"></form>
                            <table id="noticeRecord" class="table_list">
                            </table>
                            <div id="noticeRecordPager"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script th:src="@{/static/js/custom/textareaNum.js}"></script>
<!-- Page-Level Scripts -->
<script type="text/javascript">
    var tab_width = $("#tabs div.ui-tabs-panel:not(.ui-tabs-hide)").width();
    $('.grid_tab').on('shown.bs.tab',function(){
        $($(this).attr('href')).find('.table_list').jqGrid('setGridWidth',$($(this).attr('href')).find('.jqgrid_box').width());
    });
    $(function () {
        textAreaChange($("#evaluate"), 1000);
    });
    var recordSearcher = Searcher.create('#noticeRecord',
        [
            {
                label: "内容摘要", name: "content", index: "content",width:100, sortable: false
            },
            {
                label: "发送对象", name: "groupid", index: "groupid", width: 20, sortable: false,
                formatter: function (cellvalue) {
                    if (cellvalue == 1) {
                        return "店长";
                    }
                    if (cellvalue == 2){
                        return "阿姨";
                    }
                }
            },
            {label: "时间", name: "createTime", index: "createTime", width:50, sortable: false
            },
            {label: "操作", name: "option", index: "option", width:50, sortable: false,
            }

        ],
        {
            rownumbers: false, multiselect: false,
            firstLoad:false
        }
    );
    function refreshRecord() {
        recordSearcher.query($('#noticeRecordForm').getGridParam('page'));
    }

    function save() {
        var check_val = [];
        var sendKeeper = 0;
        var sendTeacher = 0;
        $.each($('input:checkbox:checked'),function(){
            check_val.push($(this).val());
            if ($(this).val() == 1){
                sendKeeper = 1;
            }
            if ($(this).val() == 2){
                sendTeacher = 1;
            }
        });
        var evaluate= $("#evaluate").val();
        if (evaluate != null && evaluate != ""){
            if (sendTeacher == 0 && sendKeeper == 0) {
                Dialog.errorMsg("请选择发送目标", function(){
                    Dialog.closeFrame(window.name)
                });
            } else {
                Page.ajaxPOST(ctxPath + "/notice/noticemessage/publish",{sendKeeper:sendKeeper,sendTeacher:sendTeacher,evaluate:evaluate}, function (res) {
                    Dialog.msg("发送成功", function(){
                        $("#evaluate").val("");
                        Dialog.closeFrame(window.name)
                    });
                });
            }

        } else {
            Dialog.errorMsg("请输入内容", function(){
                Dialog.closeFrame(window.name)
            });
        }
    }
</script>
</body>
</html>